package com.flowable.demo;

import org.flowable.form.api.FormDeployment;
import org.flowable.form.api.FormManagementService;
import org.flowable.form.api.FormRepositoryService;
import org.flowable.form.api.FormService;
import org.flowable.form.engine.FormEngine;
import org.flowable.form.engine.FormEngineConfiguration;
import org.flowable.form.engine.FormEngines;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:flowable.form.cfg.xml")
public class SpringTest {

	private FormEngine formEngine;
	
	private FormService formService;

	private FormManagementService formManagementService;

	private FormRepositoryService formRepositoryService;

	

	private FormEngineConfiguration formEngineConfiguration;
	@Before
	public void testProcessEngine() {
		formEngine =FormEngines.getDefaultFormEngine();
		System.out.println("form流程引擎类：" + formEngine);
		
		formService = formEngine.getFormService();
		System.out.println("formService：" + formService);
		
		formManagementService= formEngine.getFormManagementService();
		
		System.out.println("formManagementService：" + formManagementService);
		
		formRepositoryService = formEngine.getFormRepositoryService();
		System.out.println("formRepositoryService：" + formRepositoryService);
		
		formEngineConfiguration = formEngine.getFormEngineConfiguration();
		System.out.println("formEngineConfiguration：" + formEngineConfiguration);
		

	}
	
	/**
	 * 流程部署
	 */
	@Test
	public void deploy() {
		FormDeployment formDeployment = formRepositoryService.createDeployment()
		.category("动态表单部署")
		.addClasspathResource("自带的form引擎处理表单.bpmn20.xml")
		.deploy();
		
		System.out.println("id：" + formDeployment.getId());
		System.out.println("部署名称：" + formDeployment.getName());
		System.out.println("部署时间：" + formDeployment.getDeploymentTime());
	}
	/**
	 * 部署表单
	 */
	@Test
	public void deployForm() {
		FormDeployment formDeployment = formRepositoryService.createDeployment()
		.category("表单部署")
		.addClasspathResource("test.form")
		.deploy();
		
		System.out.println("id：" + formDeployment.getId());
		System.out.println("部署名称：" + formDeployment.getName());
		System.out.println("部署时间：" + formDeployment.getDeploymentTime());
	}

	

}